package bridge.bridge;

interface Brand{
    void info();
}

//小米品牌
class Xiaomi implements Brand{
    @Override
    public void info() {
        System.out.print("小米");
    }
}

//华为品牌
class Huawei implements Brand {
    @Override
    public void info() {
        System.out.print("华为");
    }
}

//抽象电脑类型
//abstract让Computer只能作为父类使用，必须通过子类扩展才能实例化
abstract class Computer {
    protected Brand brand;		//组合方式，创造桥

    public Computer(Brand brand) {
        this.brand = brand;
    }

    public void info() {
        brand.info();
    }
}

class Desktop extends Computer {
    public Desktop(Brand brand) {
        super(brand);
    }

    public void info() {
        super.info();
        System.out.println("台式机");
    }
}

class Laptop extends Computer {
    public Laptop(Brand brand) {
        super(brand);
    }

    public void info() {
        super.info();
        System.out.println("笔记本");
    }
}

public class BridgeTest {
    public static void main(String[] args) {
        Desktop xiaomiDesktop = new Desktop(new Xiaomi());
        xiaomiDesktop.info();

        Desktop huaweiDesktop = new Desktop(new Huawei());
        huaweiDesktop.info();

        Laptop xiaomiLaptop = new Laptop(new Xiaomi());
        xiaomiLaptop.info();

        Laptop huaweiLaptop = new Laptop(new Huawei());
        huaweiLaptop.info();
    }
}